import Vue from 'vue'
import Router from 'vue-router'

import Layout from '@/layout/Layout.vue'

Vue.use(Router)

/* Layout */
// import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/trade',
    children: [
      {
        path: 'trade',
        name: 'Trade',
        component: () => import('@/views/trade/index'),
        meta: { title: 'Trade', icon: '', affix: true, showNavbar: true, layoutBg: 'trade' }
      },
      {
        path: '/mobility',
        redirect: '/mobilityWk',
        component: () => import('@/views/mobility/index'),
        children:[
          {
            path: '/mobilityWk',
            // redirect: '/mobility',
            component: () => import('@/views/mobility/mobilityWk/index'),
          },
          {
            path: '/bond',
            component: () => import('@/views/mobility/bond/index'),
          },
          {
            path: '/staking',
            component: () => import('@/views/mobility/staking/index'),
          },
        ]
      },
      {
        path: '/data',
        redirect: '/deal',
        component: () => import('@/views/data/index'),
        children:[
          {
            path: '/deal',
            component: () => import('@/views/data/deal/index'),
          },
          {
            path: '/holdAPosition',
            component: () => import('@/views/data/holdAPosition/index'),
          },
          {
            path: '/profitAndLoAss',
            component: () => import('@/views/data/profitAndLoAss/index'),
          },
          {
            path: '/brokers',
            component: () => import('@/views/data/brokers/index'),
          },
          {
            path: '/DRF',
            component: () => import('@/views/data/DRF/index'),
          },
          {
            path: '/BDRF',
            component: () => import('@/views/data/BDRF/index'),
          },
          {
            path: '/EDRF',
            component: () => import('@/views/data/EDRF/index'),
          },
        ]
      },
      {
        path: '/broker',
        component: () => import('@/views/broker/index')
      },
      {
        path: '/extend',
        component: () => import('@/views/extend/index')
      },
      {
        path: '/help',
        component: () => import('@/views/help/index')
      },
    ]
  },
  // {
  //   path: '/tradingview',
  //   component: () => import('@/views/tradingview/index')
  // },
  // {
  //   path: '/echarts',
  //   component: () => import('@/views/echarts/index'),
  // },
  {
    path: '/ops',
    component: () => import('@/views/ops/index')
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
